function confirmEmail(){
	var isPass = true;
	$('.confirm-email').each(function(){
		var id = $(this).attr('data-target');
		if($(this).val() != $('#' + id).val()){
			$('label[data="' + $(this).attr('name') + '"]').text($(this).attr('data-msg')).show();
			$(this).addClass('errorBorder');
			isPass = false;			
		}
		else{
			$(this).attr("class", "field text medium typtxt col-sm-6 col-xs-12");
			$('label[data="' + $(this).attr('name') + '"]').text($(this).attr('data-msg')).hide();
			isPass = true;		
		}
	});
	
	return isPass;
}


function checkEmailField(obj_id, required) {
	var isPass = true;
	var this_val = document.getElementById("Field" + obj_id).value;
	emailId = $('[name="HiddenFieldID'+obj_id+'"]').val();
	emailValue = $('#Field'+obj_id).val();
	var uniqueCheck = uniqueCheckArr[obj_id];
	console.log('emailId: '+emailId);
	if (!checkTextField(obj_id, required)) {
		$('#Field'+obj_id).addClass('errorBorder');
		isPass = false;
		if(errorDisplayWay=='UseRedBoxErrorMessageInWebform')
		    document.getElementById("ErrMsg" + obj_id).style.display = "block";
	} else if (!isEmpty(this_val) && !emailValidation(this_val)) {
		$('#Field'+obj_id).addClass('errorBorder');
		isPass = false;
		 
		if(errorMsgArr[obj_id]["validErrorMsg"]!=''&&errorMsgArr[obj_id]["validErrorMsg"]!='undefined'&&errorMsgArr[obj_id]["validErrorMsg"].length > 0){
			document.getElementById("ErrMsg" + obj_id).innerHTML = errorMsgArr[obj_id]["validErrorMsg"];
			globalErrorMessage = globalErrorMessage + "\r\n"+errorMsgArr[obj_id]["validErrorMsg"];
		}
		else{
			document.getElementById("ErrMsg" + obj_id).innerHTML = "Please enter valid email address";
			globalErrorMessage = globalErrorMessage + "\r\nPlease enter valid email address";
		}
		document.getElementById("itemOnPage" + obj_id).style.display = "block";
		if(errorDisplayWay=='UseRedBoxErrorMessageInWebform')
		    document.getElementById("ErrMsg" + obj_id).style.display = "block"; 
	} else if($('#C-Field' + obj_id + '-Confirm').length > 0){
		isPass = confirmEmail();
	} else if(uniqueCheck!=0){
		emailValue = $.trim(emailValue);
		var uniqueResult = uniqueSubmitCheck(emailId,emailValue);
		if(!uniqueResult){
			$('#Field'+obj_id).addClass('errorBorder');
			isPass = false;
			if(errorMsgArr[obj_id]["uniqueErrorMsg"]!=''&&errorMsgArr[obj_id]["uniqueErrorMsg"]!='undefined'&&errorMsgArr[obj_id]["uniqueErrorMsg"].length > 0){
			document.getElementById("ErrMsg" + obj_id).innerHTML = errorMsgArr[obj_id]["uniqueErrorMsg"];
			globalErrorMessage = globalErrorMessage + "\r\n"+errorMsgArr[obj_id]["uniqueErrorMsg"];
			}
			else{
				document.getElementById("ErrMsg" + obj_id).innerHTML = "One Email can only submit once";
				globalErrorMessage = globalErrorMessage + "\r\nOne Email can only submit once";
			}
			document.getElementById("itemOnPage" + obj_id).style.display = "block";
			if(errorDisplayWay=='UseRedBoxErrorMessageInWebform')
			    document.getElementById("ErrMsg" + obj_id).style.display = "block";
		} else if(uniqueResult == 'err') {
			isPass = false;
		}
	}
	
	else {
		document.getElementById("ErrMsg" + obj_id).style.display = "none";
		document.getElementById("ErrMsg" + obj_id).innerHTML = "";
	}
	return isPass;
}